package com.luxury.adpter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.luxury.ProductActivity;
import com.luxury.R;
import com.luxury.bean.ChildType12Bean;
import com.luxury.helper.RecyclerViewAdapterHelper;

import java.util.List;

/**
 * Created by Administrator on 2016/12/19.
 */

public class Type12RecyclerAdapter extends RecyclerViewAdapterHelper<ChildType12Bean.ProductListBean> {
    private View mView=null;
    public Type12RecyclerAdapter(Context mContext, List<ChildType12Bean.ProductListBean> list) {
        super(mContext, list);
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        mView=mInflater.inflate(R.layout.item_type12recyclerview,parent,false);

        return new ViewHolderItem(mView);
    }
    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, final int position) {
        mView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int id = mList.get(position).getId();
                Intent intent=new Intent(mContext, ProductActivity.class);
                intent.putExtra("productId",id+"");
                mContext.startActivity(intent);

            }
        });
        if (holder instanceof ViewHolderItem){
            //得到产品名字
            String name = mList.get(position).getName();
            //得到产品图片地址
            String picUrl = "http://pic11.secooimg.com/product/300/300/"+mList.get(position).getPicUrl();
            //得到产品价格
            int secooPrice = mList.get(position).getSecooPrice();
            Glide.with(mContext).load(picUrl).into( ((ViewHolderItem) holder).iv_itemType12rv);
            ((ViewHolderItem) holder).tv_name_itemType12rv.setText(name);
            ((ViewHolderItem) holder).tv_price_itemType12rv.setText("￥"+secooPrice);
        }

    }
    class ViewHolderItem extends RecyclerView.ViewHolder {
        private ImageView iv_itemType12rv;
        private TextView tv_name_itemType12rv,tv_price_itemType12rv;

        public ViewHolderItem(View itemView) {
            super(itemView);
            iv_itemType12rv= (ImageView) itemView.findViewById(R.id.iv_itemType12rv);
            tv_name_itemType12rv= (TextView) itemView.findViewById(R.id.tv_name_itemType12rv);
            tv_price_itemType12rv= (TextView) itemView.findViewById(R.id.tv_price_itemType12rv);
        }
    }
}
